package cn.szzsi.business.controller.admin;

import cn.szzsi.common.util.CommonUtil;
import cn.szzsi.model.CashBank;
import com.jfinal.kit.Ret;
import com.jfinal.kit.StrKit;

import java.util.Date;

public class CashingBankController extends BaseAdminController<CashBank>{

    public void view(){
        String shopId=getAttr("shopId");
        CashBank businessCashBank=CashBank.dao.getByBid(shopId);
        setAttr("cashBank",businessCashBank);
        render(CommonUtil.TEMPLATE_PATH+"/business/cashingbank/cashing_bank_view.html");
    }

    public void edit(){
        String shopId=getAttr("shopId");
        CashBank businessCashBank=CashBank.dao.getByBid(shopId);
        setAttr("cashBank",businessCashBank);
        render("cashing_bank_edit.html");
        render(CommonUtil.TEMPLATE_PATH+"/business/cashingbank/cashing_bank_edit.html");
    }

    public void update(){
        CashBank businessCashBank=getModel(CashBank.class);
        String shopId=getAttr("shopId");
        if(StrKit.notBlank(businessCashBank.getId())){//更改
            businessCashBank.setUpdateDate(new Date());
            businessCashBank.update();
        }else {//保存
            businessCashBank.setId(StrKit.getRandomUUID());
            businessCashBank.setCreateDate(new Date());
            businessCashBank.setBid(shopId);
            businessCashBank.save();
        }
        renderJson(Ret.ok("info","操作成功!").set("url","view"));
    }

    public static void main(String[] args) {
        System.out.println(StrKit.getRandomUUID());
    }
}
